layui.use(['form','layer','table','util'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table,
        util = layui.util;

    // 任务列表
    var tableIns = table.render({
        elem: '#taskList',
        url : '/deploy/queryTaskByUser',
        cellMinWidth : 65,
        page : true,
        height : "full-125",
        limits : [10,15,20,25],
        limit : 10,
        id : "taskListTable",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'name', title: '任务名称', minWidth:100, align:"center"},
            {field: 'assignee', title: '处理人', minWidth:100, align:"center"},
            {field: 'createTime', title: '创建时间', minWidth:100, align:"center", templet:function (d) {
                return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
            }},
            {title: '操作', minWidth:175, templet:'#taskListBar', fixed:"right", align:"center"}
        ]]
    });

    //列表操作
    table.on('tool(taskList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;

        if(layEvent === 'audit'){ //审核
            audit(data);
        }else if(layEvent === 'showImg'){ //查看流程图
            showImg(data);
        }else if(layEvent === 'del'){ //删除
            layer.msg("暂未实现此功能");
        }
    });
    // 审核
    function audit(edit) {

        // gen
        var content;
        if(edit.processDefinitionId.indexOf("qjlc") >= 0){
            content = "/page/common/qjlcAudit";
        }
        if(edit.processDefinitionId.indexOf("sqjflc") >= 0){
            content = "/page/common/sqjflcAudit";
        }

        var index = layui.layer.open({
            title: "审核页面",
            type: 2,
            content: content,
            area: ['780px', '560px'],
            success: function (layero, index) {
                var body = layui.layer.getChildFrame('body', index);
                if (edit) {
                    body.find(".taskId").val(edit.id);  // 任务id
                    form.render();
                }
            }
        })
    }

    // 展示流程图
    function showImg(data) {
        var index = layui.layer.open({
            title: "流程图",
            type: 2,
            content: "/deploy/viewCurrentImageByTaskId?taskId="+data.id,
            area: ['780px', '560px'],
            success: function (layero, index) {

            }
        })
    }
});